home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Unlimited Gap Absorption.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  2.8 KB  |  107 lines  |  [TEXT/KAHL]

  1. /****************************************************************************************************
  2.     6/96 bob    Updated #includes to support changed GX Library names.
  3.     3/14/93, MD -- changed to use Hoefler Plain
  4.     
  5.     ©1990 - 1996  Apple Computer, Inc.
  6.     All rights reserved.
  7. ****************************************************************************************************/
  8.  
  9. #include <Types.h>
  10. #include <QuickDraw.h>
  11. #include <Fonts.h>
  12. #include <Windows.h>
  13. #include <Menus.h>
  14. #include <SegLoad.h>
  15. #include <Memory.h>
  16. #include <Desk.h>
  17.  
  18. #include <GXGraphics.h>
  19. #include "GraphicsLibraries.h"
  20. #include <GXEnvironment.h>
  21.  
  22. #include <GXTypes.h>
  23. #include <GXLayout.h>
  24. #include "LayoutLibrary.h"
  25.  
  26. #include "SampleInterface.h"
  27.  
  28. short MyStrLen(char *x);
  29. static short MyStrLen(x)
  30. char    *x;
  31.     {
  32.     short c = 0;
  33.     while (*x++) c++;
  34.     return c;
  35.     }    /* MyStrLen */
  36.  
  37. void UnlimitedGapAbsorption(WindowPtr sampleWindow)
  38.     {
  39.     /* Variables */
  40.     char                        *myString = "all to space";
  41.     gxGlyphcode                    glyphcodes[30];
  42.     gxGlyphJustificationOverride    glyphJustOverride;
  43.     gxLayoutOptions                gxLayoutOptions;
  44.     gxLine                        myLine;
  45.     gxPoint                        myPoint;
  46.     gxShape                        layout;
  47.     short                        len, level = 0;
  48.     gxStyle                        myStyle;
  49.     unsigned short                firstGlyph, secondGlyph;
  50.     gxViewPort                    aViewPort;
  51.     
  52.     /* Initialization */
  53.     
  54.     myPoint.x = ff(30);
  55.     myPoint.y = ff(50);
  56.     
  57.     aViewPort = GXNewWindowViewPort(sampleWindow);
  58.     SetDefaultViewPort(aViewPort);
  59.     
  60.     len = MyStrLen(myString);
  61.     
  62.     InitializeLayoutOptions(&gxLayoutOptions);
  63.     gxLayoutOptions.width = ff(500);
  64.     gxLayoutOptions.just = 0;
  65.     
  66.     myLine.first.x = myLine.last.x = myPoint.x;
  67.     myLine.first.y = 0;
  68.     myLine.last.y = ff(1000);
  69.     GXDrawLine(&myLine);
  70.     
  71.     myLine.first.x = myLine.last.x = myPoint.x + gxLayoutOptions.width;
  72.     GXDrawLine(&myLine);
  73.     
  74.     myStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(50), 0, nil, nil, 0, nil);
  75.     
  76.     layout = GXNewLayout(
  77.         1, &len, (void *) &myString,
  78.         1, &len, &myStyle,
  79.         1, &len, &level,
  80.         &gxLayoutOptions, &myPoint);
  81.     GXDrawShape(layout);
  82.     
  83.     gxLayoutOptions.just = fract1;
  84.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  85.     GXMoveShape(layout, 0, ff(75));
  86.     GXDrawShape(layout);
  87.     
  88.     GXGetLayoutGlyphs(layout, glyphcodes, nil, nil, nil, nil, nil, nil);
  89.     GXGetOffsetGlyphs(layout, 3, false, nil, &firstGlyph, &secondGlyph);
  90.  
  91.     glyphJustOverride.override.beforeGrowLimit = 0;
  92.     glyphJustOverride.override.afterGrowLimit = 0;
  93.     glyphJustOverride.override.beforeShrinkLimit = 0;
  94.     glyphJustOverride.override.afterShrinkLimit = 0;
  95.  
  96.     glyphJustOverride.glyph = glyphcodes[firstGlyph];
  97.     glyphJustOverride.override.growFlags = gxOverrideUnlimited + gxUnlimitedGapAbsorption;
  98.     glyphJustOverride.override.shrinkFlags = 0;
  99.     GXSetStyleRunGlyphJustOverrides(myStyle, 1, &glyphJustOverride);
  100.     GXMoveShape(layout, 0, ff(75));
  101.     GXDrawShape(layout);
  102.     
  103.     GXDisposeShape(layout);
  104.     GXDisposeStyle(myStyle);
  105.     GXDisposeViewPort(aViewPort);
  106.     }    /* main */
  107.